package com.app.studentActivity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.app.R;
import com.app.bean.KuaidiBean;
import com.app.bean.TushuBean;
import com.app.util.AdapterUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Kuaidi extends AppCompatActivity {

    private RecyclerView recy;
    private List<KuaidiBean> list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_kuaidi);
        initView();
        initData();
        setAdapter();
    }

    private void setAdapter() {
        AdapterUtil<KuaidiBean> adapter = new AdapterUtil<>(R.layout.tushu_item, ((data, position, holder) -> {
            TextView name = holder.getView(R.id.name);
            TextView state = holder.getView(R.id.state);
            ImageView image = holder.getView(R.id.image);
            List<Integer> list = new ArrayList<>();
            list.add(R.drawable.c1);
            list.add(R.drawable.c2);
            list.add(R.drawable.c3);
            list.add(R.drawable.c4);
            image.setImageResource(list.get(position % 4));
            name.setText(data.getName());
            state.setText(data.getState());
        }));
        adapter.listUpdate(list);
        recy.setAdapter(adapter);
    }

    private void initData() {
        list = new ArrayList<>();
        list.add(new KuaidiBean("菜鸟驿站", "科技楼一楼"));
        list.add(new KuaidiBean("极兔速递", "科1食堂门口"));
        list.add(new KuaidiBean("申通快递", "东大门门口"));
        list.add(new KuaidiBean("京东快递", "第二2教学楼门口"));
        list.add(new KuaidiBean("菜鸟驿站", "生活区1号女生寝室楼下"));
        list.add(new KuaidiBean("极兔速递", "生活区2号女生寝室楼下"));
        list.add(new KuaidiBean("申通快递", "生活区3号女生寝室楼下"));
        list.add(new KuaidiBean("京东快递", "生活区4号女生寝室楼下"));
        list.add(new KuaidiBean("菜鸟驿站", "生活区1号男生寝室楼下"));
        list.add(new KuaidiBean("极兔速递", "生活区2号男生寝室楼下"));
        list.add(new KuaidiBean("申通快递", "生活区3号男生寝室楼下"));
        list.add(new KuaidiBean("京东快递", "生活区4号男生寝室楼下"));
    }

    private void initView() {
        Toolbar toolbar = findViewById(R.id.toolbar);
        toolbar.getChildAt(0).setOnClickListener(v -> finish());
        ((TextView) toolbar.getChildAt(1)).setText("快递驿站");
        recy = findViewById(R.id.recy);
        recy.setLayoutManager(new LinearLayoutManager(this));
    }
}